const express = require('express');
const router = express.Router();
const { authenticateToken } = require('../common/auth');
const cartController = require('../controller/cartController');

/**
 * @swagger
 * /api/cart:
 *   post:
 *     tags: [Cart]
 *     summary: 添加商品到购物车
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               product_id:
 *                 type: integer
 *                 description: 商品ID（与pet_id二选一）
 *               pet_id:
 *                 type: integer
 *                 description: 宠物ID（与product_id二选一）
 *               quantity:
 *                 type: integer
 *                 default: 1
 *                 description: 数量
 *     responses:
 *       201:
 *         description: 成功添加到购物车
 */
router.post('/', authenticateToken, cartController.addToCart);

/**
 * @swagger
 * /api/cart:
 *   get:
 *     tags: [Cart]
 *     summary: 获取购物车列表
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 成功获取购物车列表
 */
router.get('/', authenticateToken, cartController.getCart);

/**
 * @swagger
 * /api/cart/{id}:
 *   put:
 *     tags: [Cart]
 *     summary: 更新购物车商品数量
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 购物车项ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - quantity
 *             properties:
 *               quantity:
 *                 type: integer
 *                 minimum: 1
 *                 description: 新的数量
 *     responses:
 *       200:
 *         description: 购物车更新成功
 */
router.put('/:id', authenticateToken, cartController.updateCartItem);

/**
 * @swagger
 * /api/cart/{id}:
 *   delete:
 *     tags: [Cart]
 *     summary: 从购物车中删除商品
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 购物车项ID
 *     responses:
 *       200:
 *         description: 成功从购物车中删除
 */
router.delete('/:id', authenticateToken, cartController.removeFromCart);

/**
 * @swagger
 * /api/cart:
 *   delete:
 *     tags: [Cart]
 *     summary: 清空购物车
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 购物车已清空
 */
router.delete('/', authenticateToken, cartController.clearCart);

module.exports = router; 